// -----------------------------------------------------------------------
//  <copyright file="HasIntegrationEventEntityBase.cs" company="LiuliuSoft">
//      Copyright (c) 2022-2023 DaprPlus. All rights reserved.
//  </copyright>
//  <site>https://www.dapr.plus</site>
//  <last-editor>郭明锋</last-editor>
//  <last-date>2023-12-25 16:50</last-date>
// -----------------------------------------------------------------------

using System.ComponentModel.DataAnnotations.Schema;


namespace DaprPlus.Domain.Entity;

/// <summary>
/// 包含集成事件的实体基类
/// </summary>
public abstract class HasIntegrationEventEntityBase : EntityBase, IHasIntegrationEvent
{
    [NotMapped]
    protected readonly List<IntegrationEvent>_IntegrationEvents = new();

    /// <summary>
    /// 集成事件集合
    /// </summary>
    [NotMapped]
    public IReadOnlyList<IntegrationEvent> IntegrationEvents => _IntegrationEvents.AsReadOnly();

    public void AddIntegrationEvent(IntegrationEvent integrationEvent)
    {
        _IntegrationEvents.Add(integrationEvent);
    }

    /// <summary>
    /// 清空当前实体内的集成事件
    /// </summary>
    public void ClearIntegrationEvents()
    {
        _IntegrationEvents.Clear();
    }
}
